package net.kts.location;

import android.app.Activity;
import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;

public class MyLocation {
	private LocationManager locationManager;
	private Criteria criteria;
	private MyLocationListener locationListener;
	String provider;
	
	public MyLocation(Activity activity) {
		super();
		this.locationManager = (LocationManager)activity.getSystemService(Context.LOCATION_SERVICE);
		this.locationListener = new MyLocationListener();
		createCriteria();
		
		provider = locationManager.getBestProvider(criteria, true);
		
		
		
		locationManager.requestLocationUpdates(provider, 10000, 10, locationListener);
	}
	
	public Location giveMeMyCurrentLocation() {
		Location location = locationManager.getLastKnownLocation(provider);
		return location;
	}
	
	public void removeUpdates(){
		locationManager.removeUpdates(locationListener);
	}
	
	public void addLocationListener(LocationListener listener){
		locationListener.addLocationListener(listener);
	}	
	
	private void createCriteria() {
		criteria = new Criteria();
		criteria.setAccuracy(Criteria.NO_REQUIREMENT);
		criteria.setAltitudeRequired(false);
		criteria.setBearingRequired(false);
		criteria.setCostAllowed(false);
		criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
	}
}
